package com.twu.biblioteca;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Map;
import java.util.Scanner;

/**
 * Created by IntelliJ IDEA.
 * User: anubhav
 * Date: 1/3/14
 * Time: 7:51 PM
 * To change this template use File | Settings | File Templates.
 */
public class BookReturn implements Action {
    private Map<String, LibraryItem> availableBooks;
    private Map<String, IssuedBook> issuedBooks;
    private PrintStream out;
    private InputSeeker in;


    public BookReturn(Map<String, LibraryItem> avlist, Map<String, IssuedBook> issuelist,
                      PrintStream out, InputSeeker in) {
        availableBooks = avlist;
        issuedBooks = issuelist;
        this.out = out;
        this.in = in;

    }


    public void executeAction() {
        String bookName;
        out.println("Please Enter Book Name");
        bookName = in.takeStringInput();
        if (issuedBooks.containsKey(bookName)) {
            bookReturn(bookName);
            out.println("Thank you for returning the book.");
        } else
            out.println("That is not a valid book to return.");
    }

    public void bookReturn(String bookName) {

        availableBooks.put(bookName, issuedBooks.get(bookName).getBook());
        issuedBooks.remove(bookName);


    }
}
